home *** CD-ROM | disk | FTP | other *** search
/ Oh!X 2001 Spring / Oh!X 2001 Spring Special CD-ROM (Japan).7z / Oh!X 2001 Spring Special CD-ROM (Japan) (Track 1).bin / GALAXY / ohx5-1 / d3dx.cpp < prev    next >
C/C++ Source or Header  |  2001-01-10  |  3KB  |  153 lines

  1. /*
  2.     Oh!X5号
  3.     GalaxyKnightsサンプル1
  4.     D3DXライブラリ手続き部分
  5. */
  6. #include    "stdafx.h"
  7. #include    "ohx5_1.h"
  8.  
  9. /*
  10.     D3DXライブラリを初期化:DX7と8で互換性無しのため、削除
  11. */
  12.  
  13. bool    init_D3DX()
  14. {
  15.     return true;
  16. }
  17.  
  18.  
  19. //    D3DXデバイスコンテキスト取得
  20. //    DirectX8では、DirectX8デバイスコンテキストそのものが無いので削除
  21.  
  22.  
  23. //    光源初期化
  24. void    init_light()
  25. {
  26. D3DLIGHT8 lg;
  27.  
  28.     ZeroMemory(&lg, sizeof(D3DLIGHT8));
  29.  
  30.     lg.Type = D3DLIGHT_DIRECTIONAL;
  31.  
  32.     lg.Diffuse.r = 1.0f;
  33.     lg.Diffuse.g = 1.0f;
  34.     lg.Diffuse.b = 1.0f;
  35.  
  36.     lg.Ambient.r = 0.3f;
  37.     lg.Ambient.g = 1.0f;
  38.     lg.Ambient.b = 2.0f;
  39.  
  40.     lg.Specular.r = 1.0f;
  41.     lg.Specular.g = 1.0f;
  42.     lg.Specular.b = 1.0f;
  43.  
  44.     lg.Position.x = 1.0f;
  45.     lg.Position.y = 9.0f;
  46.     lg.Position.z = 1.0f;
  47.  
  48.     lg.Attenuation0 = 1.0f; 
  49.     lg.Range = (float)sqrt( FLT_MAX );
  50.  
  51.     lpD3DD->SetLight(0, &lg );
  52.     lpD3DD->LightEnable(0, TRUE);
  53. }
  54.  
  55. /*
  56.     Direct3Dの動作環境をセットアップする
  57.     D3DXヘルパーライブラリとは関係の無い関数になりました。
  58. */
  59. bool start_D3DX(void)
  60. {
  61. D3DDISPLAYMODE d3ddm;
  62. D3DPRESENT_PARAMETERS d3dpp; 
  63. //    D3Dオブジェクト確保
  64.     if( NULL == (lpD3D = Direct3DCreate8(D3D_SDK_VERSION))) return false;
  65.  
  66. //    ハードウェアチェック
  67.  
  68.     if( FAILED( lpD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) ) return false;
  69.  
  70. // D3DPRESENT_PARAMETERS メンバの値を初期化
  71.  
  72.     ZeroMemory( &d3dpp,sizeof(d3dpp) );
  73.     d3dpp.BackBufferFormat                    = d3ddm.Format;                //    現在のグラフィックモード
  74.     d3dpp.BackBufferWidth                    = 640;                        // Screen width 640 pixel
  75.     d3dpp.BackBufferHeight                    = 480;                        // Screen Height 480 pixel
  76.     d3dpp.BackBufferCount                    = 1;                        // Back surface count
  77.     d3dpp.SwapEffect                        = D3DSWAPEFFECT_DISCARD;    // Screen Flip logic="Hardware FLIPPING"
  78.     d3dpp.Windowed                            = TRUE;                        // Full Screen mode
  79.     d3dpp.EnableAutoDepthStencil            = TRUE;                        // Stencil buffer disable
  80.     d3dpp.AutoDepthStencilFormat            = D3DFMT_D16;                //
  81.  
  82. //    D3Dデバイスオブジェクト確保
  83.  
  84.     if( FAILED( lpD3D->CreateDevice(
  85.                     D3DADAPTER_DEFAULT,
  86.                     D3DDEVTYPE_HAL,
  87.                     hwndApp,
  88.                     D3DCREATE_SOFTWARE_VERTEXPROCESSING,
  89.                     &d3dpp,
  90.                     &lpD3DD ) ) ) return false;
  91.  
  92.  
  93.     // Setup render state
  94.     lpD3DD->SetRenderState( D3DRS_LIGHTING,     TRUE );
  95.     lpD3DD->SetRenderState( D3DRS_DITHERENABLE, TRUE );
  96.     lpD3DD->SetRenderState( D3DRS_ZENABLE,      TRUE );
  97.     lpD3DD->SetRenderState( D3DRS_AMBIENT,      0x33333333 );
  98.     lpD3DD->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
  99.     lpD3DD->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );
  100.  
  101.     init_light();
  102.  
  103.     // マテリアル設定
  104.     D3DMATERIAL8 material;
  105.     ZeroMemory(&material, sizeof(D3DMATERIAL8));
  106.     material.Diffuse.r = 1.0f;
  107.     material.Diffuse.g = 1.0f;
  108.     material.Diffuse.b = 1.0f;
  109.     material.Specular.r = 1.0f;
  110.     material.Specular.g = 1.0f;
  111.     material.Specular.b = 1.0f;
  112.     material.Power = 3.0f;
  113. //    lpD3DD->SetMaterial(&material);
  114.  
  115.     return true;
  116. }
  117.  
  118. /*
  119.     サーフェイスの開放処理
  120. */
  121. bool release_surface(void)
  122. {
  123. //    xRelease(texp);
  124.     return true;
  125. }
  126.  
  127. /*
  128.     Direct3DXの終了処理
  129. */
  130. bool release_D3DX(void)
  131. {
  132.     xRelease(lpD3D);
  133.     xRelease(lpD3DD);
  134. //    xDelete( surface_format_list );
  135.     return true;
  136. }
  137.  
  138. /*
  139.     アプリケーション終了処理
  140.     D3DXライブラリの仕様変更で不要になりました。
  141. */
  142. bool end_application(void)
  143. {
  144. /*
  145. HRESULT hr;
  146.  
  147.     hr = D3DXUninitialize();
  148.     if (FAILED(hr)) { return false; }
  149. */
  150.     return true;
  151. }
  152.  
  153.